home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / despereaux-swings.swf / scripts / Box2D / Collision / b2BroadPhase.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  29.1 KB  |  844 lines

  1. package Box2D.Collision
  2. {
  3.    import Box2D.Common.Math.b2Math;
  4.    import Box2D.Common.Math.b2Vec2;
  5.    import Box2D.Common.b2Settings;
  6.    
  7.    public class b2BroadPhase
  8.    {
  9.       
  10.       public static var s_validate:Boolean = false;
  11.       
  12.       public static const b2_nullEdge:uint = b2Settings.USHRT_MAX;
  13.       
  14.       public static const b2_invalid:uint = b2Settings.USHRT_MAX;
  15.        
  16.       
  17.       public var m_quantizationFactor:b2Vec2;
  18.       
  19.       public var m_worldAABB:b2AABB;
  20.       
  21.       public var m_bounds:Array;
  22.       
  23.       public var m_freeProxy:uint;
  24.       
  25.       public var m_proxyCount:int;
  26.       
  27.       public var m_proxyPool:Array;
  28.       
  29.       public var m_queryResultCount:int;
  30.       
  31.       public var m_pairManager:b2PairManager;
  32.       
  33.       public var m_timeStamp:uint;
  34.       
  35.       public var m_queryResults:Array;
  36.       
  37.       public function b2BroadPhase(param1:b2AABB, param2:b2PairCallback)
  38.       {
  39.          var _loc3_:int = 0;
  40.          var _loc4_:Number = NaN;
  41.          var _loc5_:Number = NaN;
  42.          var _loc6_:b2Proxy = null;
  43.          var _loc7_:int = 0;
  44.          m_pairManager = new b2PairManager();
  45.          m_proxyPool = new Array(b2Settings.b2_maxPairs);
  46.          m_bounds = new Array(2 * b2Settings.b2_maxProxies);
  47.          m_queryResults = new Array(b2Settings.b2_maxProxies);
  48.          m_quantizationFactor = new b2Vec2();
  49.          super();
  50.          m_pairManager.Initialize(this,param2);
  51.          m_worldAABB = param1;
  52.          m_proxyCount = 0;
  53.          _loc3_ = 0;
  54.          while(_loc3_ < b2Settings.b2_maxProxies)
  55.          {
  56.             m_queryResults[_loc3_] = 0;
  57.             _loc3_++;
  58.          }
  59.          m_bounds = new Array(2);
  60.          _loc3_ = 0;
  61.          while(_loc3_ < 2)
  62.          {
  63.             m_bounds[_loc3_] = new Array(2 * b2Settings.b2_maxProxies);
  64.             _loc7_ = 0;
  65.             while(_loc7_ < 2 * b2Settings.b2_maxProxies)
  66.             {
  67.                m_bounds[_loc3_][_loc7_] = new b2Bound();
  68.                _loc7_++;
  69.             }
  70.             _loc3_++;
  71.          }
  72.          _loc4_ = param1.upperBound.x - param1.lowerBound.x;
  73.          _loc5_ = param1.upperBound.y - param1.lowerBound.y;
  74.          m_quantizationFactor.x = b2Settings.USHRT_MAX / _loc4_;
  75.          m_quantizationFactor.y = b2Settings.USHRT_MAX / _loc5_;
  76.          _loc3_ = 0;
  77.          while(_loc3_ < b2Settings.b2_maxProxies - 1)
  78.          {
  79.             _loc6_ = new b2Proxy();
  80.             m_proxyPool[_loc3_] = _loc6_;
  81.             _loc6_.SetNext(_loc3_ + 1);
  82.             _loc6_.timeStamp = 0;
  83.             _loc6_.overlapCount = b2_invalid;
  84.             _loc6_.userData = null;
  85.             _loc3_++;
  86.          }
  87.          _loc6_ = new b2Proxy();
  88.          m_proxyPool[int(b2Settings.b2_maxProxies - 1)] = _loc6_;
  89.          _loc6_.SetNext(b2Pair.b2_nullProxy);
  90.          _loc6_.timeStamp = 0;
  91.          _loc6_.overlapCount = b2_invalid;
  92.          _loc6_.userData = null;
  93.          m_freeProxy = 0;
  94.          m_timeStamp = 1;
  95.          m_queryResultCount = 0;
  96.       }
  97.       
  98.       public static function BinarySearch(param1:Array, param2:int, param3:uint) : uint
  99.       {
  100.          var _loc4_:int = 0;
  101.          var _loc5_:int = 0;
  102.          var _loc6_:int = 0;
  103.          var _loc7_:b2Bound = null;
  104.          _loc4_ = 0;
  105.          _loc5_ = param2 - 1;
  106.          while(_loc4_ <= _loc5_)
  107.          {
  108.             _loc6_ = (_loc4_ + _loc5_) / 2;
  109.             if((_loc7_ = param1[_loc6_]).value > param3)
  110.             {
  111.                _loc5_ = _loc6_ - 1;
  112.             }
  113.             else
  114.             {
  115.                if(_loc7_.value >= param3)
  116.                {
  117.                   return uint(_loc6_);
  118.                }
  119.                _loc4_ = _loc6_ + 1;
  120.             }
  121.          }
  122.          return uint(_loc4_);
  123.       }
  124.       
  125.       public function QueryAABB(param1:b2AABB, param2:*, param3:int) : int
  126.       {
  127.          var _loc4_:Array = null;
  128.          var _loc5_:Array = null;
  129.          var _loc6_:uint = 0;
  130.          var _loc7_:uint = 0;
  131.          var _loc8_:Array = null;
  132.          var _loc9_:Array = null;
  133.          var _loc10_:int = 0;
  134.          var _loc11_:int = 0;
  135.          var _loc12_:b2Proxy = null;
  136.          _loc4_ = new Array();
  137.          _loc5_ = new Array();
  138.          ComputeBounds(_loc4_,_loc5_,param1);
  139.          _loc8_ = [_loc6_];
  140.          _loc9_ = [_loc7_];
  141.          Query(_loc8_,_loc9_,_loc4_[0],_loc5_[0],m_bounds[0],2 * m_proxyCount,0);
  142.          Query(_loc8_,_loc9_,_loc4_[1],_loc5_[1],m_bounds[1],2 * m_proxyCount,1);
  143.          _loc10_ = 0;
  144.          _loc11_ = 0;
  145.          while(_loc11_ < m_queryResultCount && _loc10_ < param3)
  146.          {
  147.             _loc12_ = m_proxyPool[m_queryResults[_loc11_]];
  148.             param2[_loc11_] = _loc12_.userData;
  149.             _loc11_++;
  150.             _loc10_++;
  151.          }
  152.          m_queryResultCount = 0;
  153.          IncrementTimeStamp();
  154.          return _loc10_;
  155.       }
  156.       
  157.       public function Commit() : void
  158.       {
  159.          m_pairManager.Commit();
  160.       }
  161.       
  162.       public function GetProxy(param1:int) : b2Proxy
  163.       {
  164.          var _loc2_:b2Proxy = null;
  165.          _loc2_ = m_proxyPool[param1];
  166.          if(param1 == b2Pair.b2_nullProxy || _loc2_.IsValid() == false)
  167.          {
  168.             return null;
  169.          }
  170.          return _loc2_;
  171.       }
  172.       
  173.       private function IncrementTimeStamp() : void
  174.       {
  175.          var _loc1_:uint = 0;
  176.          if(m_timeStamp == b2Settings.USHRT_MAX)
  177.          {
  178.             _loc1_ = 0;
  179.             while(_loc1_ < b2Settings.b2_maxProxies)
  180.             {
  181.                (m_proxyPool[_loc1_] as b2Proxy).timeStamp = 0;
  182.                _loc1_++;
  183.             }
  184.             m_timeStamp = 1;
  185.          }
  186.          else
  187.          {
  188.             ++m_timeStamp;
  189.          }
  190.       }
  191.       
  192.       private function Query(param1:Array, param2:Array, param3:uint, param4:uint, param5:Array, param6:uint, param7:int) : void
  193.       {
  194.          var _loc8_:uint = 0;
  195.          var _loc9_:uint = 0;
  196.          var _loc10_:b2Bound = null;
  197.          var _loc11_:uint = 0;
  198.          var _loc12_:int = 0;
  199.          var _loc13_:int = 0;
  200.          var _loc14_:b2Proxy = null;
  201.          _loc8_ = BinarySearch(param5,param6,param3);
  202.          _loc9_ = BinarySearch(param5,param6,param4);
  203.          _loc11_ = _loc8_;
  204.          while(_loc11_ < _loc9_)
  205.          {
  206.             if((_loc10_ = param5[_loc11_]).IsLower())
  207.             {
  208.                IncrementOverlapCount(_loc10_.proxyId);
  209.             }
  210.             _loc11_++;
  211.          }
  212.          if(_loc8_ > 0)
  213.          {
  214.             _loc12_ = int(_loc8_ - 1);
  215.             _loc13_ = int((_loc10_ = param5[_loc12_]).stabbingCount);
  216.             while(_loc13_)
  217.             {
  218.                if((_loc10_ = param5[_loc12_]).IsLower())
  219.                {
  220.                   _loc14_ = m_proxyPool[_loc10_.proxyId];
  221.                   if(_loc8_ <= _loc14_.upperBounds[param7])
  222.                   {
  223.                      IncrementOverlapCount(_loc10_.proxyId);
  224.                      _loc13_--;
  225.                   }
  226.                }
  227.                _loc12_--;
  228.             }
  229.          }
  230.          param1[0] = _loc8_;
  231.          param2[0] = _loc9_;
  232.       }
  233.       
  234.       private function TestOverlapValidate(param1:b2Proxy, param2:b2Proxy) : Boolean
  235.       {
  236.          var _loc3_:int = 0;
  237.          var _loc4_:Array = null;
  238.          var _loc5_:b2Bound = null;
  239.          var _loc6_:b2Bound = null;
  240.          _loc3_ = 0;
  241.          while(_loc3_ < 2)
  242.          {
  243.             _loc5_ = (_loc4_ = m_bounds[_loc3_])[param1.lowerBounds[_loc3_]];
  244.             _loc6_ = _loc4_[param2.upperBounds[_loc3_]];
  245.             if(_loc5_.value > _loc6_.value)
  246.             {
  247.                return false;
  248.             }
  249.             _loc5_ = _loc4_[param1.upperBounds[_loc3_]];
  250.             _loc6_ = _loc4_[param2.lowerBounds[_loc3_]];
  251.             if(_loc5_.value < _loc6_.value)
  252.             {
  253.                return false;
  254.             }
  255.             _loc3_++;
  256.          }
  257.          return true;
  258.       }
  259.       
  260.       private function ComputeBounds(param1:Array, param2:Array, param3:b2AABB) : void
  261.       {
  262.          var _loc4_:Number = NaN;
  263.          var _loc5_:Number = NaN;
  264.          var _loc6_:Number = NaN;
  265.          var _loc7_:Number = NaN;
  266.          _loc4_ = param3.lowerBound.x;
  267.          _loc5_ = param3.lowerBound.y;
  268.          _loc4_ = b2Math.b2Min(_loc4_,m_worldAABB.upperBound.x);
  269.          _loc5_ = b2Math.b2Min(_loc5_,m_worldAABB.upperBound.y);
  270.          _loc4_ = b2Math.b2Max(_loc4_,m_worldAABB.lowerBound.x);
  271.          _loc5_ = b2Math.b2Max(_loc5_,m_worldAABB.lowerBound.y);
  272.          _loc6_ = param3.upperBound.x;
  273.          _loc7_ = param3.upperBound.y;
  274.          _loc6_ = b2Math.b2Min(_loc6_,m_worldAABB.upperBound.x);
  275.          _loc7_ = b2Math.b2Min(_loc7_,m_worldAABB.upperBound.y);
  276.          _loc6_ = b2Math.b2Max(_loc6_,m_worldAABB.lowerBound.x);
  277.          _loc7_ = b2Math.b2Max(_loc7_,m_worldAABB.lowerBound.y);
  278.          param1[0] = uint(m_quantizationFactor.x * (_loc4_ - m_worldAABB.lowerBound.x)) & b2Settings.USHRT_MAX - 1;
  279.          param2[0] = uint(m_quantizationFactor.x * (_loc6_ - m_worldAABB.lowerBound.x)) & 65535 | 1;
  280.          param1[1] = uint(m_quantizationFactor.y * (_loc5_ - m_worldAABB.lowerBound.y)) & b2Settings.USHRT_MAX - 1;
  281.          param2[1] = uint(m_quantizationFactor.y * (_loc7_ - m_worldAABB.lowerBound.y)) & 65535 | 1;
  282.       }
  283.       
  284.       public function CreateProxy(param1:b2AABB, param2:*) : uint
  285.       {
  286.          var _loc3_:uint = 0;
  287.          var _loc4_:b2Proxy = null;
  288.          var _loc5_:uint = 0;
  289.          var _loc6_:uint = 0;
  290.          var _loc7_:Array = null;
  291.          var _loc8_:Array = null;
  292.          var _loc9_:int = 0;
  293.          var _loc10_:int = 0;
  294.          var _loc11_:Array = null;
  295.          var _loc12_:uint = 0;
  296.          var _loc13_:uint = 0;
  297.          var _loc14_:Array = null;
  298.          var _loc15_:Array = null;
  299.          var _loc16_:Array = null;
  300.          var _loc17_:int = 0;
  301.          var _loc18_:int = 0;
  302.          var _loc19_:b2Bound = null;
  303.          var _loc20_:b2Bound = null;
  304.          var _loc21_:b2Bound = null;
  305.          var _loc22_:int = 0;
  306.          var _loc23_:b2Proxy = null;
  307.          _loc5_ = m_freeProxy;
  308.          _loc4_ = m_proxyPool[_loc5_];
  309.          m_freeProxy = _loc4_.GetNext();
  310.          _loc4_.overlapCount = 0;
  311.          _loc4_.userData = param2;
  312.          _loc6_ = uint(2 * m_proxyCount);
  313.          _loc7_ = new Array();
  314.          _loc8_ = new Array();
  315.          ComputeBounds(_loc7_,_loc8_,param1);
  316.          _loc9_ = 0;
  317.          while(_loc9_ < 2)
  318.          {
  319.             _loc11_ = m_bounds[_loc9_];
  320.             _loc14_ = [_loc12_];
  321.             _loc15_ = [_loc13_];
  322.             Query(_loc14_,_loc15_,_loc7_[_loc9_],_loc8_[_loc9_],_loc11_,_loc6_,_loc9_);
  323.             _loc12_ = uint(_loc14_[0]);
  324.             _loc13_ = uint(_loc15_[0]);
  325.             _loc16_ = new Array();
  326.             _loc18_ = _loc6_ - _loc13_;
  327.             _loc17_ = 0;
  328.             while(_loc17_ < _loc18_)
  329.             {
  330.                _loc16_[_loc17_] = new b2Bound();
  331.                _loc19_ = _loc16_[_loc17_];
  332.                _loc20_ = _loc11_[int(_loc13_ + _loc17_)];
  333.                _loc19_.value = _loc20_.value;
  334.                _loc19_.proxyId = _loc20_.proxyId;
  335.                _loc19_.stabbingCount = _loc20_.stabbingCount;
  336.                _loc17_++;
  337.             }
  338.             _loc18_ = int(_loc16_.length);
  339.             _loc22_ = _loc13_ + 2;
  340.             _loc17_ = 0;
  341.             while(_loc17_ < _loc18_)
  342.             {
  343.                _loc20_ = _loc16_[_loc17_];
  344.                (_loc19_ = _loc11_[int(_loc22_ + _loc17_)]).value = _loc20_.value;
  345.                _loc19_.proxyId = _loc20_.proxyId;
  346.                _loc19_.stabbingCount = _loc20_.stabbingCount;
  347.                _loc17_++;
  348.             }
  349.             _loc16_ = new Array();
  350.             _loc18_ = _loc13_ - _loc12_;
  351.             _loc17_ = 0;
  352.             while(_loc17_ < _loc18_)
  353.             {
  354.                _loc16_[_loc17_] = new b2Bound();
  355.                _loc19_ = _loc16_[_loc17_];
  356.                _loc20_ = _loc11_[int(_loc12_ + _loc17_)];
  357.                _loc19_.value = _loc20_.value;
  358.                _loc19_.proxyId = _loc20_.proxyId;
  359.                _loc19_.stabbingCount = _loc20_.stabbingCount;
  360.                _loc17_++;
  361.             }
  362.             _loc18_ = int(_loc16_.length);
  363.             _loc22_ = _loc12_ + 1;
  364.             _loc17_ = 0;
  365.             while(_loc17_ < _loc18_)
  366.             {
  367.                _loc20_ = _loc16_[_loc17_];
  368.                (_loc19_ = _loc11_[int(_loc22_ + _loc17_)]).value = _loc20_.value;
  369.                _loc19_.proxyId = _loc20_.proxyId;
  370.                _loc19_.stabbingCount = _loc20_.stabbingCount;
  371.                _loc17_++;
  372.             }
  373.             _loc13_++;
  374.             _loc19_ = _loc11_[_loc12_];
  375.             _loc20_ = _loc11_[_loc13_];
  376.             _loc19_.value = _loc7_[_loc9_];
  377.             _loc19_.proxyId = _loc5_;
  378.             _loc20_.value = _loc8_[_loc9_];
  379.             _loc20_.proxyId = _loc5_;
  380.             _loc21_ = _loc11_[int(_loc12_ - 1)];
  381.             _loc19_.stabbingCount = _loc12_ == 0 ? 0 : _loc21_.stabbingCount;
  382.             _loc21_ = _loc11_[int(_loc13_ - 1)];
  383.             _loc20_.stabbingCount = _loc21_.stabbingCount;
  384.             _loc3_ = _loc12_;
  385.             while(_loc3_ < _loc13_)
  386.             {
  387.                ++(_loc21_ = _loc11_[_loc3_]).stabbingCount;
  388.                _loc3_++;
  389.             }
  390.             _loc3_ = _loc12_;
  391.             while(_loc3_ < _loc6_ + 2)
  392.             {
  393.                _loc19_ = _loc11_[_loc3_];
  394.                _loc23_ = m_proxyPool[_loc19_.proxyId];
  395.                if(_loc19_.IsLower())
  396.                {
  397.                   _loc23_.lowerBounds[_loc9_] = _loc3_;
  398.                }
  399.                else
  400.                {
  401.                   _loc23_.upperBounds[_loc9_] = _loc3_;
  402.                }
  403.                _loc3_++;
  404.             }
  405.             _loc9_++;
  406.          }
  407.          ++m_proxyCount;
  408.          _loc10_ = 0;
  409.          while(_loc10_ < m_queryResultCount)
  410.          {
  411.             m_pairManager.AddBufferedPair(_loc5_,m_queryResults[_loc10_]);
  412.             _loc10_++;
  413.          }
  414.          m_pairManager.Commit();
  415.          m_queryResultCount = 0;
  416.          IncrementTimeStamp();
  417.          return _loc5_;
  418.       }
  419.       
  420.       public function DestroyProxy(param1:uint) : void
  421.       {
  422.          var _loc2_:b2Bound = null;
  423.          var _loc3_:b2Bound = null;
  424.          var _loc4_:b2Proxy = null;
  425.          var _loc5_:int = 0;
  426.          var _loc6_:int = 0;
  427.          var _loc7_:int = 0;
  428.          var _loc8_:Array = null;
  429.          var _loc9_:uint = 0;
  430.          var _loc10_:uint = 0;
  431.          var _loc11_:uint = 0;
  432.          var _loc12_:uint = 0;
  433.          var _loc13_:Array = null;
  434.          var _loc14_:int = 0;
  435.          var _loc15_:int = 0;
  436.          var _loc16_:int = 0;
  437.          var _loc17_:uint = 0;
  438.          var _loc18_:int = 0;
  439.          var _loc19_:b2Proxy = null;
  440.          _loc4_ = m_proxyPool[param1];
  441.          _loc5_ = 2 * m_proxyCount;
  442.          _loc6_ = 0;
  443.          while(_loc6_ < 2)
  444.          {
  445.             _loc8_ = m_bounds[_loc6_];
  446.             _loc9_ = uint(_loc4_.lowerBounds[_loc6_]);
  447.             _loc10_ = uint(_loc4_.upperBounds[_loc6_]);
  448.             _loc2_ = _loc8_[_loc9_];
  449.             _loc11_ = _loc2_.value;
  450.             _loc3_ = _loc8_[_loc10_];
  451.             _loc12_ = _loc3_.value;
  452.             _loc13_ = new Array();
  453.             _loc15_ = _loc10_ - _loc9_ - 1;
  454.             _loc14_ = 0;
  455.             while(_loc14_ < _loc15_)
  456.             {
  457.                _loc13_[_loc14_] = new b2Bound();
  458.                _loc2_ = _loc13_[_loc14_];
  459.                _loc3_ = _loc8_[int(_loc9_ + 1 + _loc14_)];
  460.                _loc2_.value = _loc3_.value;
  461.                _loc2_.proxyId = _loc3_.proxyId;
  462.                _loc2_.stabbingCount = _loc3_.stabbingCount;
  463.                _loc14_++;
  464.             }
  465.             _loc15_ = int(_loc13_.length);
  466.             _loc16_ = int(_loc9_);
  467.             _loc14_ = 0;
  468.             while(_loc14_ < _loc15_)
  469.             {
  470.                _loc3_ = _loc13_[_loc14_];
  471.                _loc2_ = _loc8_[int(_loc16_ + _loc14_)];
  472.                _loc2_.value = _loc3_.value;
  473.                _loc2_.proxyId = _loc3_.proxyId;
  474.                _loc2_.stabbingCount = _loc3_.stabbingCount;
  475.                _loc14_++;
  476.             }
  477.             _loc13_ = new Array();
  478.             _loc15_ = _loc5_ - _loc10_ - 1;
  479.             _loc14_ = 0;
  480.             while(_loc14_ < _loc15_)
  481.             {
  482.                _loc13_[_loc14_] = new b2Bound();
  483.                _loc2_ = _loc13_[_loc14_];
  484.                _loc3_ = _loc8_[int(_loc10_ + 1 + _loc14_)];
  485.                _loc2_.value = _loc3_.value;
  486.                _loc2_.proxyId = _loc3_.proxyId;
  487.                _loc2_.stabbingCount = _loc3_.stabbingCount;
  488.                _loc14_++;
  489.             }
  490.             _loc15_ = int(_loc13_.length);
  491.             _loc16_ = int(_loc10_ - 1);
  492.             _loc14_ = 0;
  493.             while(_loc14_ < _loc15_)
  494.             {
  495.                _loc3_ = _loc13_[_loc14_];
  496.                _loc2_ = _loc8_[int(_loc16_ + _loc14_)];
  497.                _loc2_.value = _loc3_.value;
  498.                _loc2_.proxyId = _loc3_.proxyId;
  499.                _loc2_.stabbingCount = _loc3_.stabbingCount;
  500.                _loc14_++;
  501.             }
  502.             _loc15_ = _loc5_ - 2;
  503.             _loc17_ = _loc9_;
  504.             while(_loc17_ < _loc15_)
  505.             {
  506.                _loc2_ = _loc8_[_loc17_];
  507.                _loc19_ = m_proxyPool[_loc2_.proxyId];
  508.                if(_loc2_.IsLower())
  509.                {
  510.                   _loc19_.lowerBounds[_loc6_] = _loc17_;
  511.                }
  512.                else
  513.                {
  514.                   _loc19_.upperBounds[_loc6_] = _loc17_;
  515.                }
  516.                _loc17_++;
  517.             }
  518.             _loc15_ = int(_loc10_ - 1);
  519.             _loc18_ = int(_loc9_);
  520.             while(_loc18_ < _loc15_)
  521.             {
  522.                _loc2_ = _loc8_[_loc18_];
  523.                --_loc2_.stabbingCount;
  524.                _loc18_++;
  525.             }
  526.             Query([0],[0],_loc11_,_loc12_,_loc8_,_loc5_ - 2,_loc6_);
  527.             _loc6_++;
  528.          }
  529.          _loc7_ = 0;
  530.          while(_loc7_ < m_queryResultCount)
  531.          {
  532.             m_pairManager.RemoveBufferedPair(param1,m_queryResults[_loc7_]);
  533.             _loc7_++;
  534.          }
  535.          m_pairManager.Commit();
  536.          m_queryResultCount = 0;
  537.          IncrementTimeStamp();
  538.          _loc4_.userData = null;
  539.          _loc4_.overlapCount = b2_invalid;
  540.          _loc4_.lowerBounds[0] = b2_invalid;
  541.          _loc4_.lowerBounds[1] = b2_invalid;
  542.          _loc4_.upperBounds[0] = b2_invalid;
  543.          _loc4_.upperBounds[1] = b2_invalid;
  544.          _loc4_.SetNext(m_freeProxy);
  545.          m_freeProxy = param1;
  546.          --m_proxyCount;
  547.       }
  548.       
  549.       public function TestOverlap(param1:b2BoundValues, param2:b2Proxy) : Boolean
  550.       {
  551.          var _loc3_:int = 0;
  552.          var _loc4_:Array = null;
  553.          var _loc5_:b2Bound = null;
  554.          _loc3_ = 0;
  555.          while(_loc3_ < 2)
  556.          {
  557.             _loc5_ = (_loc4_ = m_bounds[_loc3_])[param2.upperBounds[_loc3_]];
  558.             if(param1.lowerValues[_loc3_] > _loc5_.value)
  559.             {
  560.                return false;
  561.             }
  562.             _loc5_ = _loc4_[param2.lowerBounds[_loc3_]];
  563.             if(param1.upperValues[_loc3_] < _loc5_.value)
  564.             {
  565.                return false;
  566.             }
  567.             _loc3_++;
  568.          }
  569.          return true;
  570.       }
  571.       
  572.       public function Validate() : void
  573.       {
  574.          var _loc1_:b2Pair = null;
  575.          var _loc2_:b2Proxy = null;
  576.          var _loc3_:b2Proxy = null;
  577.          var _loc4_:Boolean = false;
  578.          var _loc5_:int = 0;
  579.          var _loc6_:b2Bound = null;
  580.          var _loc7_:uint = 0;
  581.          var _loc8_:uint = 0;
  582.          var _loc9_:uint = 0;
  583.          var _loc10_:b2Bound = null;
  584.          _loc5_ = 0;
  585.          while(_loc5_ < 2)
  586.          {
  587.             _loc6_ = m_bounds[_loc5_];
  588.             _loc7_ = uint(2 * m_proxyCount);
  589.             _loc8_ = 0;
  590.             _loc9_ = 0;
  591.             while(_loc9_ < _loc7_)
  592.             {
  593.                if((_loc10_ = _loc6_[_loc9_]).IsLower() == true)
  594.                {
  595.                   _loc8_++;
  596.                }
  597.                else
  598.                {
  599.                   _loc8_--;
  600.                }
  601.                _loc9_++;
  602.             }
  603.             _loc5_++;
  604.          }
  605.       }
  606.       
  607.       private function IncrementOverlapCount(param1:uint) : void
  608.       {
  609.          var _loc2_:b2Proxy = null;
  610.          _loc2_ = m_proxyPool[param1];
  611.          if(_loc2_.timeStamp < m_timeStamp)
  612.          {
  613.             _loc2_.timeStamp = m_timeStamp;
  614.             _loc2_.overlapCount = 1;
  615.          }
  616.          else
  617.          {
  618.             _loc2_.overlapCount = 2;
  619.             m_queryResults[m_queryResultCount] = param1;
  620.             ++m_queryResultCount;
  621.          }
  622.       }
  623.       
  624.       public function InRange(param1:b2AABB) : Boolean
  625.       {
  626.          var _loc2_:Number = NaN;
  627.          var _loc3_:Number = NaN;
  628.          var _loc4_:Number = NaN;
  629.          var _loc5_:Number = NaN;
  630.          _loc2_ = param1.lowerBound.x;
  631.          _loc3_ = param1.lowerBound.y;
  632.          _loc2_ -= m_worldAABB.upperBound.x;
  633.          _loc3_ -= m_worldAABB.upperBound.y;
  634.          _loc4_ = m_worldAABB.lowerBound.x;
  635.          _loc5_ = m_worldAABB.lowerBound.y;
  636.          _loc4_ -= param1.upperBound.x;
  637.          _loc5_ -= param1.upperBound.y;
  638.          _loc2_ = b2Math.b2Max(_loc2_,_loc4_);
  639.          _loc3_ = b2Math.b2Max(_loc3_,_loc5_);
  640.          return b2Math.b2Max(_loc2_,_loc3_) < 0;
  641.       }
  642.       
  643.       public function MoveProxy(param1:uint, param2:b2AABB) : void
  644.       {
  645.          var _loc3_:Array = null;
  646.          var _loc4_:* = 0;
  647.          var _loc5_:uint = 0;
  648.          var _loc6_:uint = 0;
  649.          var _loc7_:b2Bound = null;
  650.          var _loc8_:b2Bound = null;
  651.          var _loc9_:b2Bound = null;
  652.          var _loc10_:uint = 0;
  653.          var _loc11_:b2Proxy = null;
  654.          var _loc12_:uint = 0;
  655.          var _loc13_:b2Proxy = null;
  656.          var _loc14_:b2BoundValues = null;
  657.          var _loc15_:b2BoundValues = null;
  658.          var _loc16_:Array = null;
  659.          var _loc17_:uint = 0;
  660.          var _loc18_:uint = 0;
  661.          var _loc19_:uint = 0;
  662.          var _loc20_:uint = 0;
  663.          var _loc21_:int = 0;
  664.          var _loc22_:int = 0;
  665.          var _loc23_:uint = 0;
  666.          var _loc24_:b2Proxy = null;
  667.          if(param1 == b2Pair.b2_nullProxy || b2Settings.b2_maxProxies <= param1)
  668.          {
  669.             return;
  670.          }
  671.          if(param2.IsValid() == false)
  672.          {
  673.             return;
  674.          }
  675.          _loc12_ = uint(2 * m_proxyCount);
  676.          _loc13_ = m_proxyPool[param1];
  677.          _loc14_ = new b2BoundValues();
  678.          ComputeBounds(_loc14_.lowerValues,_loc14_.upperValues,param2);
  679.          _loc15_ = new b2BoundValues();
  680.          _loc5_ = 0;
  681.          while(_loc5_ < 2)
  682.          {
  683.             _loc7_ = m_bounds[_loc5_][_loc13_.lowerBounds[_loc5_]];
  684.             _loc15_.lowerValues[_loc5_] = _loc7_.value;
  685.             _loc7_ = m_bounds[_loc5_][_loc13_.upperBounds[_loc5_]];
  686.             _loc15_.upperValues[_loc5_] = _loc7_.value;
  687.             _loc5_++;
  688.          }
  689.          _loc5_ = 0;
  690.          while(_loc5_ < 2)
  691.          {
  692.             _loc16_ = m_bounds[_loc5_];
  693.             _loc17_ = uint(_loc13_.lowerBounds[_loc5_]);
  694.             _loc18_ = uint(_loc13_.upperBounds[_loc5_]);
  695.             _loc19_ = uint(_loc14_.lowerValues[_loc5_]);
  696.             _loc20_ = uint(_loc14_.upperValues[_loc5_]);
  697.             _loc7_ = _loc16_[_loc17_];
  698.             _loc21_ = _loc19_ - _loc7_.value;
  699.             _loc7_.value = _loc19_;
  700.             _loc7_ = _loc16_[_loc18_];
  701.             _loc22_ = _loc20_ - _loc7_.value;
  702.             _loc7_.value = _loc20_;
  703.             if(_loc21_ < 0)
  704.             {
  705.                _loc6_ = _loc17_;
  706.                while(_loc6_ > 0 && _loc19_ < (_loc16_[int(_loc6_ - 1)] as b2Bound).value)
  707.                {
  708.                   _loc7_ = _loc16_[_loc6_];
  709.                   _loc23_ = (_loc8_ = _loc16_[int(_loc6_ - 1)]).proxyId;
  710.                   _loc24_ = m_proxyPool[_loc8_.proxyId];
  711.                   ++_loc8_.stabbingCount;
  712.                   if(_loc8_.IsUpper() == true)
  713.                   {
  714.                      if(TestOverlap(_loc14_,_loc24_))
  715.                      {
  716.                         m_pairManager.AddBufferedPair(param1,_loc23_);
  717.                      }
  718.                      _loc3_ = _loc24_.upperBounds;
  719.                      _loc4_ = (_loc4_ = int(_loc3_[_loc5_])) + 1;
  720.                      _loc3_[_loc5_] = _loc4_;
  721.                      ++_loc7_.stabbingCount;
  722.                   }
  723.                   else
  724.                   {
  725.                      _loc3_ = _loc24_.lowerBounds;
  726.                      _loc4_ = (_loc4_ = int(_loc3_[_loc5_])) + 1;
  727.                      _loc3_[_loc5_] = _loc4_;
  728.                      --_loc7_.stabbingCount;
  729.                   }
  730.                   _loc3_ = _loc13_.lowerBounds;
  731.                   _loc4_ = (_loc4_ = int(_loc3_[_loc5_])) - 1;
  732.                   _loc3_[_loc5_] = _loc4_;
  733.                   _loc7_.Swap(_loc8_);
  734.                   _loc6_--;
  735.                }
  736.             }
  737.             if(_loc22_ > 0)
  738.             {
  739.                _loc6_ = _loc18_;
  740.                while(_loc6_ < _loc12_ - 1 && (_loc16_[int(_loc6_ + 1)] as b2Bound).value <= _loc20_)
  741.                {
  742.                   _loc7_ = _loc16_[_loc6_];
  743.                   _loc10_ = (_loc9_ = _loc16_[int(_loc6_ + 1)]).proxyId;
  744.                   _loc11_ = m_proxyPool[_loc10_];
  745.                   ++_loc9_.stabbingCount;
  746.                   if(_loc9_.IsLower() == true)
  747.                   {
  748.                      if(TestOverlap(_loc14_,_loc11_))
  749.                      {
  750.                         m_pairManager.AddBufferedPair(param1,_loc10_);
  751.                      }
  752.                      _loc3_ = _loc11_.lowerBounds;
  753.                      _loc4_ = (_loc4_ = int(_loc3_[_loc5_])) - 1;
  754.                      _loc3_[_loc5_] = _loc4_;
  755.                      ++_loc7_.stabbingCount;
  756.                   }
  757.                   else
  758.                   {
  759.                      _loc3_ = _loc11_.upperBounds;
  760.                      _loc4_ = (_loc4_ = int(_loc3_[_loc5_])) - 1;
  761.                      _loc3_[_loc5_] = _loc4_;
  762.                      --_loc7_.stabbingCount;
  763.                   }
  764.                   _loc3_ = _loc13_.upperBounds;
  765.                   _loc4_ = (_loc4_ = int(_loc3_[_loc5_])) + 1;
  766.                   _loc3_[_loc5_] = _loc4_;
  767.                   _loc7_.Swap(_loc9_);
  768.                   _loc6_++;
  769.                }
  770.             }
  771.             if(_loc21_ > 0)
  772.             {
  773.                _loc6_ = _loc17_;
  774.                while(_loc6_ < _loc12_ - 1 && (_loc16_[int(_loc6_ + 1)] as b2Bound).value <= _loc19_)
  775.                {
  776.                   _loc7_ = _loc16_[_loc6_];
  777.                   _loc10_ = (_loc9_ = _loc16_[int(_loc6_ + 1)]).proxyId;
  778.                   _loc11_ = m_proxyPool[_loc10_];
  779.                   --_loc9_.stabbingCount;
  780.                   if(_loc9_.IsUpper())
  781.                   {
  782.                      if(TestOverlap(_loc15_,_loc11_))
  783.                      {
  784.                         m_pairManager.RemoveBufferedPair(param1,_loc10_);
  785.                      }
  786.                      _loc3_ = _loc11_.upperBounds;
  787.                      _loc4_ = (_loc4_ = int(_loc3_[_loc5_])) - 1;
  788.                      _loc3_[_loc5_] = _loc4_;
  789.                      --_loc7_.stabbingCount;
  790.                   }
  791.                   else
  792.                   {
  793.                      _loc3_ = _loc11_.lowerBounds;
  794.                      _loc4_ = (_loc4_ = int(_loc3_[_loc5_])) - 1;
  795.                      _loc3_[_loc5_] = _loc4_;
  796.                      ++_loc7_.stabbingCount;
  797.                   }
  798.                   _loc3_ = _loc13_.lowerBounds;
  799.                   _loc4_ = (_loc4_ = int(_loc3_[_loc5_])) + 1;
  800.                   _loc3_[_loc5_] = _loc4_;
  801.                   _loc7_.Swap(_loc9_);
  802.                   _loc6_++;
  803.                }
  804.             }
  805.             if(_loc22_ < 0)
  806.             {
  807.                _loc6_ = _loc18_;
  808.                while(_loc6_ > 0 && _loc20_ < (_loc16_[int(_loc6_ - 1)] as b2Bound).value)
  809.                {
  810.                   _loc7_ = _loc16_[_loc6_];
  811.                   _loc23_ = (_loc8_ = _loc16_[int(_loc6_ - 1)]).proxyId;
  812.                   _loc24_ = m_proxyPool[_loc23_];
  813.                   --_loc8_.stabbingCount;
  814.                   if(_loc8_.IsLower() == true)
  815.                   {
  816.                      if(TestOverlap(_loc15_,_loc24_))
  817.                      {
  818.                         m_pairManager.RemoveBufferedPair(param1,_loc23_);
  819.                      }
  820.                      _loc3_ = _loc24_.lowerBounds;
  821.                      _loc4_ = (_loc4_ = int(_loc3_[_loc5_])) + 1;
  822.                      _loc3_[_loc5_] = _loc4_;
  823.                      --_loc7_.stabbingCount;
  824.                   }
  825.                   else
  826.                   {
  827.                      _loc3_ = _loc24_.upperBounds;
  828.                      _loc4_ = (_loc4_ = int(_loc3_[_loc5_])) + 1;
  829.                      _loc3_[_loc5_] = _loc4_;
  830.                      ++_loc7_.stabbingCount;
  831.                   }
  832.                   _loc3_ = _loc13_.upperBounds;
  833.                   _loc4_ = (_loc4_ = int(_loc3_[_loc5_])) - 1;
  834.                   _loc3_[_loc5_] = _loc4_;
  835.                   _loc7_.Swap(_loc8_);
  836.                   _loc6_--;
  837.                }
  838.             }
  839.             _loc5_++;
  840.          }
  841.       }
  842.    }
  843. }
  844.